package net.siufung.market.base.permit.provider;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import net.siufung.market.base.app.spi.ICheckMenuOccupySpi;
import net.siufung.market.base.permit.mapper.IMenuMapper;
import net.siufung.market.base.permit.mapper.entity.Menu;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 陈建峰
 * @date 2023/1/13 6:02 PM
 * @since V1.0.0
 */
@AllArgsConstructor
public class CheckMenuOccupyProvider implements ICheckMenuOccupySpi {

    private final IMenuMapper menuMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean allowRemove(Integer appId) {
        if(menuMapper.selectCount(
                new LambdaQueryWrapper<Menu>().eq(Menu::getAppId, appId)) > 0){
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    @Override
    public boolean allowStatus(Integer appId) {
        if(menuMapper.selectCount(
                new LambdaQueryWrapper<Menu>().eq(Menu::getAppId, appId)) > 0){
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }
}
